package com.example.myndklearn

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Environment
import kotlinx.android.synthetic.main.activity_main.*
import java.io.File

class MainActivity : AppCompatActivity() {

    var mainNative = MainNative()

    var ndkFileUtils = NDKFileUtils()


    var bsPath = BsPath()

    var array = intArrayOf(10, 5, 21, 3, 17, 3, 12)
    var videoPath = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "1-1.mp4"
    var videoPathPattern = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "1-1_%d.mp4"

    var liuyanPath = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "liuyan.jpg"

    var apkOldPath = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "old.apk"
    var apkNewPath = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "new2.apk"
    var apkPatchPath = Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "old-new.patch"


    // 路径不能使用中文可能会出现
    var cryptLiuyanPath =
        Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "crtpyLiuyan.jpg"
    var decryptLiuyanPath =
        Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "decrtpyLiuyan.jpg"

    var liuyanPathPattern =
        Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "liuyanPattern_%d.jpg"

    var liuyanPathPatch =
        Environment.getExternalStorageDirectory().absolutePath + File.separatorChar + "liuyanPathch.jpg"

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        mainNative.chaneStaticIntValue()
//
//        // Example of a call to a native method
//        sample_text.text =
//            mainNative.stringFromJNI() + mainNative.handleBooleanFromJNI() + "    --- " + MainNative.keyValue
//
//        mainNative.assessMethod()
//
//        Log.e(MainActivity::class.java.name, " assessMethod  == " + MainNative.keyValue)
//
//        val date = mainNative.accessConstructor()
//        Log.e(MainActivity::class.java.name, date.toString())

//        mainNative.callHumanSyaHi()


//        mainNative.handleArray(array)
//        for (intValue in array){
//            Log.d(MainActivity::class.java.name, "排序值 ~ $intValue")
//        }

//        Log.d(MainActivity::class.java.name, Gson().toJson(array))
//
//        Log.d(MainActivity::class.java.name, Gson().toJson(mainNative.getIntArray(10)))
//
//        Log.e(MainActivity::class.java.name, "=================我是分割线===================")
//
//        mainNative.createGlobalString()
//
//        Log.w(MainActivity::class.java.name, "全局" + mainNative.globalString)
//
//        mainNative.deleteGlobalString()


        // 文件加密解密
        crypt.setOnClickListener {
            mainNative.cryptFile(
                liuyanPath, cryptLiuyanPath
            )
        }

        decrypt.setOnClickListener {
            mainNative.decryptFile(
                cryptLiuyanPath, decryptLiuyanPath
            )
        }

        // 分割合并文件
//        ndkFileUtils.diffFile(liuyanPath, liuyanPathPattern, 4)
//
//        ndkFileUtils.patchFile(liuyanPathPattern, liuyanPathPatch, 4)

        // 增量更新
        bsPath.apkPatch(apkOldPath, apkNewPath, apkPatchPath)

    }

}
